extends Slot
class_name Equipment_Slot

# Called when the node enters the scene tree for the first time.
func swap_item_with_mouse_slot(is_back: bool = false):
	if mouse_slot:
		print("SLOT_SWAPED")
		var temp_dic:Dictionary = {}
		var temp_pandora = null
		
		## 如果mouse_slot没有装备，先移走当前格子的装备
		if mouse_slot.item_info_dict.is_empty():
			mouse_slot.item_info_dict = self.item_info_dict#移走的格子
			mouse_slot.item_pandora = self.item_pandora
			if mouse_slot.item_pandora:
				Utils.minus_to_player(mouse_slot.item_pandora)
			self.item_info_dict = temp_dic
			self.item_pandora = temp_pandora
			mouse_slot.last_slot = self
			update_item_info_dict()
			return 	
		
		if not mouse_slot.item_info_dict.has("type"):
			update_item_info_dict()
			return
		
		## 开始交换两个格子的值
		if item_pandora:
			Utils.minus_to_player(self.item_pandora)
		
		## 先获取光标的
		temp_dic = mouse_slot.item_info_dict.duplicate()
		temp_pandora = mouse_slot.item_pandora.duplicate()
		
		var last_slot = mouse_slot.last_slot
		if last_slot and not is_back:
			last_slot.item_info_dict = self.item_info_dict
			last_slot.item_pandora = self.item_pandora
			last_slot.update_item_info_dict()
			if last_slot is Equipment_Slot and last_slot.item_pandora:
				Utils.add_to_player(last_slot.item_pandora)
			
		self.item_info_dict = temp_dic
		self.item_pandora = temp_pandora
		
		Utils.add_to_player(self.item_pandora)
		mouse_slot.last_slot = null
		mouse_slot.clear_mouse_slot()
		print(item_info_dict)
	else:
		print("mouse_slot NULL")
	update_item_info_dict()
